import { UserInfo } from "../common/UserInfo"
import { Events } from "./Events"

export class BManager {
    /**建筑物的id */
    gid: number
    /**建筑物的等级 */
    grade: number = 0
    instantHint: string
    /**建筑物的坑位 */
    uid: number
    
    static createByObj(obj):BManager{
        let b = new BManager()

        for(let key in obj){
            b[key] = obj[key]
        }

        return b

    }

    /**根据uid查找 BMananger */
    static getBManage(uid: number): BManager {
        let villageData = UserInfo.instance.villageData
        for (let b of villageData.bManager.bList) {
            if (b.uid == uid) {
                return this.createByObj(b)
            }
        }
        return null
    }

     /**根据gid(id)查找 BMananger */
    static getBManageById(gid:number):BManager{
        let villageData = UserInfo.instance.villageData
        for (let b of villageData.bManager.bList) {
            if (b.gid == gid) {
                return this.createByObj(b)
            }
        }
        return null
    }

    /**
     * 根据id 和 等级查找
     * @param id 
     * @param level 
     */
    static findByIdAndLevel(id:number,level:number):BManager{
        let villageData = UserInfo.instance.villageData
        for (let b of villageData.bManager.bList) {
            if (b.gid == id && b.grade >= level) {
                return this.createByObj(b)
            }
        }
        return null
    }
}
